package com.ruoyi.bizsys.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.math.BigDecimal;
import java.util.Date;

import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 奖励分销比对象 award_distribution_ratio
 *
 * @author african-loan
 * @date 2022-06-24
 */

@Data
public class AwardDistributionRatio extends BaseEntity {
    private static final long serialVersionUID = 1L;


    /**
     * $column.columnComment
     */

    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    @TableId(type = IdType.AUTO)
    private Long id;


    /**
     * 分销比例Name
     */
    @Excel(name = "分销比例Name")
    private String name;


    /**
     * 分销层级
     */
    @Excel(name = "分销层级")
    private Integer level;


    /**
     * 一级分销比例
     */
    @Excel(name = "一级分销比例")
    private Integer firstRatio;


    /**
     * 二级分销比例
     */
    @Excel(name = "二级分销比例")
    private Integer secondRatio;


    /**
     * 三级分销比例
     */
    @Excel(name = "三级分销比例")
    private Integer thirdRatio;


    /**
     * $column.columnComment
     */
    @Excel(name = "三级分销比例")
    private String state;


    /**
     * 备注
     */

    @Excel(name = "备注")
    private String remark;


    /**
     * 创建者
     */

    @Excel(name = "备注")
    private String createBy;


    /**
     * 创建时间
     */

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "备注", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;


    /**
     * 更新者
     */
    @Excel(name = "备注")
    private String updateBy;


    /**
     * 更新时间
     */

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "备注", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;


    public BigDecimal tieredBonus(BigDecimal awardPrincipal, int level) {
        switch (level) {
            case 1:
                return awardPrincipal.multiply(new BigDecimal(String.valueOf(firstRatio))).multiply(new BigDecimal("0.01")).setScale(4,BigDecimal.ROUND_DOWN);
            case 2:
                return awardPrincipal.multiply(new BigDecimal(String.valueOf(secondRatio))).multiply(new BigDecimal("0.01")).setScale(4,BigDecimal.ROUND_DOWN);
            case 3:
                return awardPrincipal.multiply(new BigDecimal(String.valueOf(thirdRatio))).multiply(new BigDecimal("0.01")).setScale(4,BigDecimal.ROUND_DOWN);
            default:
                return awardPrincipal;
        }

    }

}